/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. 
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. 
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. 
 * Vestibulum commodo. Ut rhoncus gravida arcu. 
 */

/**
 * 算术运算符
 */
public class Demo03 {

    public static void main(String[] args) {
//        test1();
//        test2();
        test3();
    }

    public static  void test3(){
        float a = 0.123456789f;//精度丢失问题 0.12345679
//        a = 123.456789f;
//        a = 1234567890f;
        System.out.println(a);
    }

    /**
     * ++i 与 i++
     * i = i+1;
     */
    public static void test2() {

        int i = 1;
        int s = ++i;
        int x = i++;

        System.out.println(i);
        System.out.println(s);
        System.out.println(x);

        i=3;
        i = i++;
        System.out.println(i);
    }

    /**
     * + - * / %
     */
    public static void test1() {
        System.out.println(4 / 5L);
        System.out.println(1 + 2 * 3 - 4 / 5);
        System.out.println(1 + 2 * 3.0 - 4 / 5);
        System.out.println(1 + 2 * 3.0 - 4 / 5.0);
        // 优先级: 负号 优先 */% 优先 +- 运算
        // 运算结果类型提升:运算符的结果类型为两边表达式中类型更广泛的类型
        System.out.println(5 % 3);//2
        System.out.println(-5 % 3);//-2
        System.out.println(5 % -3);//2
        System.out.println(-5 % -3);//-2
        //取余的结果的正负取决于被取余的数
        char a = 'a';
        a += 1;
        System.out.println(a);
        //操作数:数值(byte,short,int ,long,float,double,char)

//        int i1 = 10;
//        int i2 = 0;
//        int i3 = i1/i2;//java.lang.ArithmeticException: / by zero
//        System.out.println(i3);
        // 整数不能除0

        double d1 = 10.0;
        double d2 = 0.0;
        double d3 = d1 / d2;//Infinity
        System.out.println(d3);
        System.out.println(Double.isInfinite(d3));
        //浮点类型除0不会抛异常,结果为Infinity(无穷大)


    }

}
